<?php
/* These are the variable that tell the subject of the email and where the email will be sent. */

//$earlMarshalEmail = "rik@rik-scarborough.com";
$earlMarshalEmail = "martino@kc.rr.com";

$deputyEmail =  array("Deputy/Central Region"=>"Deputy/Central Region <DMCentral@calontir.org>",
    "Deputy/Northwest Region"=>"Deputy/Northwest Region <DMNorthwest@calontir.org>",
    "Deputy/Northeast Region"=>"Deputy/Northeast Region <DMNortheast@calontir.org>",
    "Deputy/East Region"=>"Deputy/East Region <DMEast@calontir.org>",
    "Deputy/West Region"=>"Deputy/West Region <DMWest@calontir.org>", 
    "Deputy/South Region"=>"Deputy/South Region <DMSouth@calontir.org>");

$emailSubject = 'Marshal Report';


/* These will gather what the user has typed into the fieled. */

$ReportingPeriod = $_POST['reportingperiod'];
$DeputyMarshal = $_POST['deputymarshal'];
$MarshalType = $_POST['MarshalType'];
$CC = $_POST['CCField'];
$SCAName = $_POST['SCAName'];
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$address = $_POST['address'];
$city = $_POST['city'];
$state = $_POST['state'];
$zip = $_POST['zip'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$membershipnumber = $_POST['membershipnumber'];
$membershipexpires = $_POST['membershipexpires'];
$homegroup = $_POST['homegroup'];
$numFighters = $_POST['numfighters'];
$numMinors = $_POST['numminors'];
$activities = $_POST['activities'];
$problems = $_POST['problems'];
$summary = $_POST['summary'];
$eventReport = $_POST['eventreport'];
$event = $_POST['event'];

if ($MarshalType == "Regional Deputy") {
    $mailto = $earlMarshalEmail;
} else {
    $mailto = $deputyEmail[$DeputyMarshal];
}

if ($MarshalType == "Group") {
    $emailSubject .= " for " . $homegroup;
}

if ($MarshalType == "Event") {
    $emailSubject = "Event report for " . $event . " - " . $SCAName;
} else {
    $emailSubject .= " - " . $SCAName . " - " . $ReportingPeriod;
}

if(empty ($MarshalType)) {
      header('Location: /marshal-report.php');
      exit();
}

/* This takes the information and lines it up the way you want it to be sent in the email. */

if ($MarshalType == "Event") {
$body = <<<EOD

Report

Event: $event
Marshal Type: $MarshalType
SCA Name:  $SCAName 
Modern First & Last Name: $firstname $lastname
Address: $address 
City, State, Zip: $city, $state  $zip
Phone Number: $phone
Membership Number: $membershipnumber
Membership Expires: $membershipexpires
Home Group: $homegroup
Number of Authorized Fighters: $numFighters
Number of Minors: $numMinors
Event Report: $eventReport
Activities: $activities
Problems or Injuries: $problems
Summary: $summary


EOD;

} else {
$body = <<<EOD

Report

Reporting Period: $ReportingPeriod 
Marshal Type: $MarshalType
SCA Name:  $SCAName 
Modern First & Last Name: $firstname $lastname
Address: $address 
City, State, Zip: $city, $state  $zip
Phone Number: $phone
Membership Number: $membershipnumber
Membership Expires: $membershipexpires
Home Group: $homegroup
Number of Authorized Fighters: $numFighters
Number of Minors: $numMinors
Activities: $activities
Problems or Injuries: $problems
Summary: $summary


EOD;

}

//$earlMarshalEmail = 'rik@rik-scarborough.com';
//$mailto = 'riksca@gmail.com';

if ($CC == 'Email CC' || $CC == 'Email.CC') {
    $CCLine = 'Cc: ' . $earlMarshalEmail . ', ' . $email . "\r\n";
} else {
    $CCLine = 'Cc: ' . $earlMarshalEmail . ', ' . $email . ', ' . $CC . "\r\n";
}


$headers = "From: no-reply@calontir.org\r\n"; // This displays who the e-mail is from.  Please leave the default value of no-reply@calontir.org. Do not use $email - doing so will leave the code vulnerable to a header injection exploit.
$headers .= $CCLine;
$success = mail($mailto, $emailSubject, $body, $headers); // This tells the server what to send.
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
        <title>Marshal Report Form &raquo; Kingdom of Calontir</title>
        <meta name="description" content=" " />
        <meta name="keywords" content="Calontir" />
        <meta name="MSSmartTagsPreventParsing" content="TRUE" />
        <meta http-equiv="imagetoolbar" content="no" />
        <meta name="author" content="Jennifer Langley" />
        <meta name="copyright" content="Copyright � 2010 - present Jennifer Langley, Kingdom of Calontir, SCA, Inc." />
        <meta name="expires" content="Dec 21 2012" />
        <style type="text/css" media="all">@import "http://www.calontir.org/files/css/kocm_layout.css";</style>
        <style type="text/css" media="all">@import "http://www.calontir.org/files/css/kocm_form.css";</style>
        <!--[if lt IE 8]>
        <link rel="stylesheet" type="text/css" href="http://www.calontir.org/files/css/iehacks.css" />
        <![endif]-->
        <link rel="stylesheet" href="http://www.calontir.org/files/css/kocm_layout_print.css" media="print" />
        <link rel="alternate stylesheet" title="lucida : font" href="http://www.calontir.org/files/css/theme/lucida.css" media="screen" />
        <link rel="alternate stylesheet" title="calibri : font" href="http://www.calontir.org/files/css/theme/calibri.css" media="screen" />
        <link rel="alternate stylesheet" title="palontino : font" href="http://www.calontir.org/files/css/theme/palontino.css" media="screen" />
        <link rel="alternate stylesheet" title="lcolumn : layout" href="http://www.calontir.org/files/css/theme/lcolumn.css" media="screen" />
        <link rel="alternate stylesheet" title="onecolumn : layout" href="http://www.calontir.org/files/css/theme/onecolumn.css" media="screen" />
        <link rel="shortcut icon" href="http://www.calontir.org/files/ico/calontir-arms.ico" />
        <script type="text/javascript" src="http://www.calontir.org/files/js/kocm_tweak.js"></script>
        <script type="text/javascript" src="http://www.calontir.org/files/js/kocm_form_tweak.js"></script>
    </head>
    <body>
        <div id="sleeve">
            <div id="book">
                <?php include @ ("http://www.calontir.org/files/php/nav/header.php"); ?>
                <?php include @ ("http://www.calontir.org/files/php/ran/songs.php"); ?>
                <?php include @ ("http://www.calontir.org/files/php/nav/h_menu.php"); ?>
                <?php include @ ("http://www.calontir.org/files/php/nav/v_menu.php"); ?>

                <div id="left-column">
                    <div class="panel">
                        <h1><a name="content" id="content" tabindex="3000"><strong>Marshal</strong> <strong>R</strong>eport <strong>F</strong>orm</a></h1>
                        <?php if($success) { ?>
                        <div class="yellow-bg" style="border:1px solid #deb887;padding:0px 6px;width:300px;"><p>Thank you!<br />
                                Your report has been sent.</p></div>
                        <?php } else { ?>
                        <div class="yellow-bg" style="border:1px solid #deb887;padding:0px 6px;width:300px;">
                            <p>There was an error, your report was not sent. Contact the person who maintains this page
                            and try again later.</p></div>
                        <?php } ?>
                    </div>

                </div>

                <?php include @ ("footer.php"); ?>
            </div>
        </div>
    </body>
</html>
